package cn.stylefeng.guns.modular.util.itext;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.IOException;
import java.net.URL;

/**
 * @Description:
 * @Author jzy
 * @Date 2020/10/12 0012
 **/
class ImgWatermarkEvent extends PdfPageEventHelper {

    URL picPath ;

    public ImgWatermarkEvent(URL picPath) {
        this.picPath = picPath;
    }

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        try {
            Image image = Image.getInstance(picPath);
            image.setAlignment(Image.UNDERLYING);
            image.setAbsolutePosition(100, 600);
            image.scaleAbsolute(400,100);//自定义大小
            document.add(image);
            Image image2 = Image.getInstance(picPath);
            image2.setAlignment(Image.UNDERLYING);
            // 设置坐标 绝对位置 X Y
            image2.setAbsolutePosition(100, 200);
            image2.scaleAbsolute(400,100);//自定义大小
            document.add(image2);
        } catch (BadElementException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        super.onEndPage(writer, document);
    }
}
